package com.yy.finvideoplayer

/**
 * @Description: HandlePlayListener
 * @Author: yiw89
 * @CreateDate: 2025/9/1 15:16
 * @Version: 1.0
 */
class HandlePlayListener : PlayListener {
    private var setPlayListener: PlayListener? = null
    private var playListenerSet: MutableList<PlayListener> = mutableListOf<PlayListener>()

    /*override fun onStatus(status: Int) {
        if (playListenerSet != null) for (p in playListenerSet) p.onStatus(status)
    }

    override fun onMode(mode: Int) {
        if (playListenerSet != null) for (p in playListenerSet) p.onMode(mode)
    }*/

    override fun onStatusAndMode(status: Int, mode: Int) {
        if (playListenerSet != null) for (p in playListenerSet) p.onStatusAndMode(status, mode)
    }

    override fun onEvent(what: Int, vararg extra: Int?) {
        if (playListenerSet != null) for (p in playListenerSet) p.onEvent(what, *extra)
    }


    fun setListener(playListener: PlayListener?) {
        removeListener(setPlayListener)
        if (playListener != null) {
            setPlayListener = playListener
            addListener(playListener)
        }
    }

    fun addListener(playListener: PlayListener?) {
        if (playListener == null) return
        if (playListenerSet == null) playListenerSet = mutableListOf<PlayListener>()
        playListenerSet!!.add(playListener)
    }

    fun removeListener(playListener: PlayListener?) {
        if (playListenerSet == null || playListener == null) return
        playListenerSet!!.remove(playListener)
    }
}
